#include<iostream>
#include<cmath>
#include<string>
using namespace std;
class Time;
class Date;
void display(const Date &d, const Time &t);
class Date
{
    private:
        int year,month,day;
    public:
        Date(int _y,int _m,int _d):year(_y),month(_m),day(_d){ }
        friend void display(const Date &d, const Time &t);
};
class Time
{
    private:
        int hour,min,secon;
    public:
        Time(int _h,int _m,int _s):hour(_h),min(_m),secon(_s){ }
        friend void display(const Date &d, const Time &t);
};
void display(const Date &d, const Time &t)
{
    printf("%04d-%02d-%02d %02d:%02d:%02d\n",d.year,d.month,d.day,t.hour,t.min,t.secon);
}
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
        int a,b,c,d,e,f;
        cin>>a>>b>>c;
        Date tmpa(a,b,c);
        cin>>d>>e>>f;
        Time tmpb(d,e,f);
        display(tmpa,tmpb);
    }
}